package com.woniuxy.springbootpro.service.impl;

import com.woniuxy.springbootpro.entity.Root;
import com.woniuxy.springbootpro.entity.User;
import com.woniuxy.springbootpro.mapper.UserMapper;
import com.woniuxy.springbootpro.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class UserServiceImpl implements UserService {

    private UserMapper userMapper;

    @Autowired
    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public User findById(Integer id) {
        return userMapper.findById(id);
    }

    @Override
    public List<User> findAll() {
        return userMapper.findAll();
    }

    @Override
    public boolean add(User user) {
        return userMapper.add(user) != 0;
    }

    @Override
    public boolean delete(Integer id) {
        return userMapper.delete(id) != 0;
    }

    @Override
    public boolean updata(User user) {
        return userMapper.update(user) != 0;
    }

    @Override
    public User findUserByNameAndPwd(User user) {
        return userMapper.findUserByNameAndPwd(user);
    }

    @Override
    public List<Root> findUserPermission(int userId) {
        return userMapper.findUserRootById(userId);
    }
}
